package follow.juc.heima.day8;

import jdk.nashorn.internal.ir.CallNode;

import java.util.HashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Demo9Compare {
    public void main(String[] args) {
        AtomicLong atomicLong = new AtomicLong(0L);
        LongAdder longAdder = new LongAdder();

        long start = System.currentTimeMillis();
        for (int i = 0; i < 50; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int j = 0; j < 100000; j++) {
                        //longAdder.increment();
                        atomicLong.incrementAndGet();
                    }

                }
            }).start();
        }
        while (Thread.activeCount() > 2) {
            /*AbstractQueuedSynchronizer*/
            ReentrantLock lock = new ReentrantLock();
            lock.lock();


            ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();

            lock.unlock();
        }

        System.out.println(atomicLong.get());
        System.out.println(longAdder.longValue());

        System.out.println("耗时:" + (System.currentTimeMillis() - start));

    }
}
